package cm.day12;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Test5 {
    static int num = 1;
    static Object object = new Object();

    public static void main(String[] args) {
        Thread th1 = new Thread(() -> {
            while (num < 100) {
                synchronized (object) {
                    if ((num % 2) == 1) {
                        System.out.println("奇数" + num++);
                    }
                }
            }
        });

            Thread th2 = new Thread(() -> {
                while (num < 100) {
                    synchronized (object) {
                        if ((num % 2) == 0) {
                            System.out.println("偶数" + num++);
                        }
                    }
                }

        });
            th1.start();
            th2.start();

    }
}
